<!DOCTYPE html>
<html>
    <head>
        <meta charset="utf-8">
        <title></title>
        <script>
            var str = "abcoefoxyozzopp";
            var index = str.indexOf('o');
            var num = 0;
            while (index !== -1) {
                console.log(index);
                num++;
                index = str.indexOf('o', index + 1);
            }
            console.log('o出现的次数' + num);
        </script>
    </head>
    <body>
    </body>
</html>
